package com.wbdgj.ui.home;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;

import com.google.gson.internal.LinkedTreeMap;
import com.wbdgj.R;
import com.wbdgj.adapter.CompaignAdapter;
import com.wbdgj.adapter.MessageAdapter;
import com.wbdgj.base.BaseApplication;
import com.wbdgj.base.BaseFragment;
import com.wbdgj.http.HttpAdapter;
import com.wbdgj.http.OnResponseListener;
import com.wbdgj.model.ResultMessageObjectModel;
import com.wbdgj.model.ResultObjectModel;
import com.wbdgj.utils.ListViewForScrollView;
import com.wbdgj.utils.SpKeyUtils;
import com.wbdgj.utils.ToastUtils;

import java.text.DecimalFormat;
import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;
import retrofit2.Call;

/**
 * Created by Administrator on 2018/5/2.
 */

public class WbDetail02Fragment extends BaseFragment{

    private Context context;
    private String id;
    @BindView(R.id.demo_listview)
    ListViewForScrollView demo_listview;
    private CompaignAdapter compaignAdapter;
    @Override
    protected int getLayout() {
        return R.layout.ui_wb_detail_02;
    }

    @Override
    protected void onInit() {
        context = getActivity();
        id = getActivity().getIntent().getStringExtra("id");
        appbranchactivity();
        demo_listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                DecimalFormat decimalFormat = new DecimalFormat("###################.###########");
                if (!compaignAdapter.hasNoData){
                    startActivity(new Intent(context, CampaignDetailActivity.class).putExtra("id", compaignAdapter.getItem(i).get("cloud_id")+""));
                }
            }
        });
    }

    @OnClick({})
    public void onClick(View view) {
        switch (view.getId()) {
//            case R.id.yhq:
//                startActivity(new Intent(context, YhqActivity.class).putExtra("id",id));
//                break;

        }
    }

    @Override
    public void fetchData() {

    }

    private void appbranchactivity() {
        Call<ResultObjectModel> call = HttpAdapter.getSerives().appnbnactivity(id, "2");
        call.enqueue(new OnResponseListener<ResultObjectModel>(context) {
            @Override
            protected void onSuccess(ResultObjectModel userModelBaseResultModel) {
                if(userModelBaseResultModel.getResultCode().equals("0000")){
                    DecimalFormat decimalFormat = new DecimalFormat("###################.###########");
                    LinkedTreeMap linkedTreeMap = (LinkedTreeMap) userModelBaseResultModel.getData();
                    ArrayList<LinkedTreeMap> arrayList = (ArrayList<LinkedTreeMap>) linkedTreeMap.get("data");
                    compaignAdapter = new CompaignAdapter(context, arrayList);
                    demo_listview.setAdapter(compaignAdapter);
                }else{
                    ToastUtils.toastShort(userModelBaseResultModel.getResultMsg());
                }
            }
        });
    }
}
